package com.gms.service.equipmanager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gms.entity.equipment.Equipment;
import com.gms.mapper.EquipmentMapper;
import com.gms.service.equipmanager.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jianghai
 * @since 2021-06-14
 */
@Service
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements EquipmentService {

    @Autowired
    private EquipmentMapper mapper;

    @Override
    public void addEquipment(Equipment equipment) {
        equipment.setStatus("1");
        mapper.insert(equipment);
    }

    @Override
    public void delEquipment(Integer eId) {
        mapper.deleteById(eId);
    }

    @Override
    public void alterEquipment(Equipment equipment) {
        mapper.updateById(equipment);
    }

    @Override
    public List<Equipment> queryEquipment() {
        return mapper.selectList(null);
    }

    @Override
    public Equipment queryById(Integer eId) {
        return mapper.selectById(eId);
    }

    @Override
    public Page<Equipment> select_page(Integer pagenum) {
        Page<Equipment> page = new Page<>(pagenum,5);
        return mapper.selectPage(page,null);
    }

    @Override
    public Page<Equipment> select_page(Integer pagenum, Integer size) {
        return null;
    }

    @Override
    public Equipment queryByName(String etypename) {
        QueryWrapper<Equipment> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(etypename)) {
            wrapper.eq("etypename",etypename);
        }
        return mapper.selectOne(wrapper);
    }

    @Override
    public Page<Equipment> query_equip(String etypename, Integer eTypeId, Integer pageNum) {
        Page<Equipment> page = new Page<>(pageNum,5);

        QueryWrapper<Equipment> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(etypename)) {
            wrapper.like("etypename",etypename);
        }
        if (eTypeId != null) {
            wrapper.like("eTypeId",eTypeId);
        }
        return mapper.selectPage(page,wrapper);
    }
}
